
l = ["d", "f", "u", "l", "r"]
from itertools import product, compress, starmap
from sketchz import *
# ~ al = product(*[range(2) for i in range(5)])

# ~ print(list(al))
# ~ exit()

def f():
    for i in range(32):
        s = bin(32 +i)[3:]
        r = [int(ch) for ch in s]
        print(r)
        yield r

def f2(n):
    for i in range(2**n):
        s = bin(2**n +i)[3:]
        r = [int(ch) for ch in s]
        yield r
                

al = f()
all = (list(a for k, a in zip(x, l) if k) for x in al)



tab = {
"f": U3(0, 1, 0), 
"u": U3(0, 0, 1), 
"d": U3(0, 0, -1), 
"l": U3(-1, 0, 0), 
"r": U3(1, 0, 0), 
}
    
data = []

datadata = []

cache = set()

for x in all:
    te = [tab[s] for s in x]
    mirror = frozenset((-v[0], v[1], v[2]) for v in te)
    if mirror not in cache:
        data.append(te)
        cache.add(frozenset((tab[s][0], tab[s][1], tab[s][2]) for s in x))
        
print(len(data))        

def rep(l):
    return [(v[0], v[1], v[2]) for v in l]

ext = {
1: [U3(1, 0, 1),U3(1, 1, 0),U3(1, 0, -1),],
2: [U3(1, 0, 1),U3(1, 1, 0),U3(1, 0, -1),U3(-1, 0, 1),U3(-1, 1, 0),U3(-1, 0, -1),],
3: [U3(-1, 0, 1), U3(1, 0, 1), U3(0, 1, 1), ],
4: [U3(-1, 0, 1), U3(0, 1, 1), U3(1, 1, 0), U3(1, 0, -1), ],
5: [U3(-1, 1, 0), U3(-1, 0, -1), U3(0, 1, 1), U3(1, 1, 0), U3(1, 0, -1),],
6: [U3(1, 0, 0), U3(-1, 0, 0), U3(0, 0, 1), U3(0, 0, -1), ],
7: [U3(-1, 0, 0), U3(0, 0, 1), U3(0, 0, -1), U3(1, 0, 1), U3(1, 0, -1), ],
8: [U3(0, 0, 1), U3(0, 0, -1), U3(1, 0, 1), U3(1, 0, -1), U3(-1, 0, 1), U3(-1, 0, -1), ],
9: [U3(-1, 1, 0), U3(1, 1, 0), U3(0, 1, -1), U3(1, 0, 1), U3(-1, 0, 1), ],
10: [U3(-1, 1, 0), U3(0, 1, -1), U3(-1, 0, 1), U3(1, 0, -1), ],
11: [U3(-1, 0, -1), U3(1, 0, -1), U3(0, 1, -1), ],
12: [U3(-1, 0, -1), U3(1, 0, -1), U3(0, 1, -1), ],
13: [U3(-1, 0, -1), U3(0, 1, -1), U3(1, 1, 0), U3(1, 0, 1), ],
14: [U3(-1, 0, 1), U3(1, 0, 1), U3(-1, 1, 0), U3(1, 1, 0), U3(0, 1, -1), ],
15: [U3(-1, 0, 1), U3(1, 0, 1), U3(0, 1, 1), U3(-1, 0, -1), U3(1, 0, -1), U3(0, 1, -1), ],
16: [U3(-1, 0, 1), U3(-1, 0, -1), U3(0, 1, 1), U3(0, 1, -1), U3(1, 1, 0), ],
17: [V3(1, 0, -1), V3(-1, 0, -1), V3(0, 1, -1), V3(0, -1, -1), ],
18: [V3(-1, 0, -1), V3(1, 0, -1), V3(0, 1, -1), V3(-1, -1, 0), V3(1, -1, 0), ],
19: [V3(-1, 0, -1), V3(0, 1, -1), V3(-1, -1, 0), V3(1, 1, 0), ],
20: [V3(-1, 1, 0), V3(1, 1, 0), V3(0, 1, -1), ],
21: [V3(-1, 1, 0), V3(1, 1, 0), V3(-1, -1, 0), V3(-1, 1, 0), V3(1, 0, -1), V3(-1, 0, -1), ],
22: [V3(-1, 0, -1), V3(-1,1, 0), V3(-1, -1, 0), ],
}

for i in range(1, 23):
    print(">>", i, len(data))
    acc = []
    x = data[i]
    ex = ext[i]
    for rr in f2(len(ex)):
        
        that = list(a for k, a in zip(rr, ex) if k)
        that = x + that
        
        mirror = frozenset((-v[0], v[1], v[2]) for v in that)
        if mirror not in cache:
            acc.append(that)
            cache.add(frozenset((v[0], v[1], v[2]) for v in that))
    datadata.append(acc)

print(len(data))
# ~ exit()

# ~ for i in range(5):
    # ~ print(data[24+i])
# ~ exit()

window = WindowAfter((100, 100))
window.img.clear_value = (0.6, 0.7, 0.8, 1)


walker = Walker3(window.camera)
window.camera.t.pos = U3(0, -1.3, 0)
walker >> window


obj = make_block(U3(1, 1, 1))
obj.color = V3(1,1, 1)

obj.u(window)
obj >> window

ddd = sum(datadata, [])
print(len(ddd))
exit()
# ~ for iii, acc in enumerate(datadata):
for iii in range(4):
    # ~ data_part = acc
    data_part = ddd[110*iii:110*(iii+1)]
    print("part", len(data_part))
    
    canvas = np.ones((1000, 1100, 3), dtype="uint8") * 255


    box = make_block(U3(1, 1, 1))

    

    for ij, l in enumerate(data_part):
        i, j  = divmod(ij, 11)
        # ~ print(i, j)
        # ~ i,j = 5 - j, i
        if len(l) == 0:
            print("0")
            obj.t.pos = U3(100, 0, 0)
            window.render()
            arr = np.frombuffer(window.img2.read(), dtype="f4").reshape((100, 100, 4))
            canvas[i * 100: i*100+100, j * 100: j * 100 + 100, :] = (arr[:, :, :3] * 255).astype("uint8")
            obj.t.pos = U3(0, 0, 0)
            continue

    
        obj.vertices = []
        obj.normals = []
        
        
        for p in l:
            box.t.pos = p*1.035
            box.as_unit() >> obj
            
            
        obj.u(window)
        
        window.render()
        sdl2.SDL_GL_SwapWindow(window.window)
        sdl2.SDL_Delay(20)
        
        arr = np.frombuffer(window.img2.read(), dtype="f4").reshape((100, 100, 4))
            
        canvas[i * 100: i*100+100, j * 100: j * 100 + 100, :] = (arr[::-1, :, :3] * 255).astype("uint8")


    for i in range(11):
        canvas[:, i * 100-2:i*100+2, :] = 0
    for i in range(10):
        canvas[i * 100-2:i*100+2, :, :] = 0





# ~ window.mainloop()

    from PIL import Image
    img = Image.fromarray(canvas, mode="RGB")
    img.save(f"tableb{iii}.png", format="PNG")


